package com.hsylient.javase.chapter10;

import org.junit.Test;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.Calendar;
import java.util.TimeZone;

public class MyCalendar {

    private static final Calendar calendar = Calendar.getInstance();

    @Test
    public void testGetInstance() {
        System.out.println(Calendar.getInstance());
        System.out.println(Calendar.getInstance(TimeZone.getDefault()));
    }

    @Test
    public void testGetAvailableLocales() {
        System.out.println(Arrays.toString(Calendar.getAvailableLocales()));
    }

    @Test
    public void testGetTime() {
        System.out.println(Calendar.getInstance().getTime());
    }

    @Test
    public void testGet() {
        System.out.println(calendar.get(Calendar.YEAR));
        // 小1
        System.out.println(calendar.get(Calendar.MONTH));
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
    }

    public static void getCalendarView() {
        System.out.println(String.join(" ", "Mon", "Tue", "Web", "thu", "Fri", "sat", "Sun"));
        LocalDate now = LocalDate.now();
        LocalDate oneDay = now.minusDays(now.getDayOfMonth() - 1);
        int value = oneDay.getDayOfWeek().getValue();
        for (int i = 0; i < value; i++) {
            System.out.print("\t");
        }
        while (oneDay.getMonthValue() == now.getMonthValue()) {
            if (oneDay.getDayOfWeek().getValue() == 6) {
                System.out.println(oneDay.getDayOfMonth());
            } else if (oneDay.getDayOfMonth() == now.getDayOfMonth()) {
                System.out.print(oneDay.getDayOfMonth() + "* ");
            } else {
                System.out.print(oneDay.getDayOfMonth() + "\t");
            }
            oneDay = oneDay.plusDays(1L);
        }
    }
}
